package us.ajg0702.leaderboards.libs.hikari.metrics.prometheus;

import io.prometheus.client.Collector;
import io.prometheus.client.CollectorRegistry;
import us.ajg0702.leaderboards.libs.hikari.metrics.IMetricsTracker;
import us.ajg0702.leaderboards.libs.hikari.metrics.MetricsTrackerFactory;
import us.ajg0702.leaderboards.libs.hikari.metrics.PoolStats;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


public class PrometheusMetricsTrackerFactory
        implements MetricsTrackerFactory {
    private static final Map<CollectorRegistry, RegistrationStatus> registrationStatuses = new ConcurrentHashMap<>();

    private final HikariCPCollector collector = new HikariCPCollector();

    private final CollectorRegistry collectorRegistry;

    public PrometheusMetricsTrackerFactory() {
        this(CollectorRegistry.defaultRegistry);
    }


    public PrometheusMetricsTrackerFactory(CollectorRegistry collectorRegistry) {
        this.collectorRegistry = collectorRegistry;
    }

    public IMetricsTracker create(String poolName, PoolStats poolStats) {
        registerCollector(this.collector, this.collectorRegistry);
        this.collector.add(poolName, poolStats);
        return new PrometheusMetricsTracker(poolName, this.collectorRegistry, this.collector);
    }

    private void registerCollector(Collector collector, CollectorRegistry collectorRegistry) {
        if (registrationStatuses.putIfAbsent(collectorRegistry, RegistrationStatus.REGISTERED) == null)
            collector.register(collectorRegistry);
    }


    public enum RegistrationStatus {
        REGISTERED
    }
}


*Location:D:\User\Xuan\Downloads\ajLeaderboards-1.3.3.jar\\us\ajg0702\leaderboards\libs\hikari\metrics\prometheus\PrometheusMetricsTrackerFactory.class
 *Java compiler version:8(52.0)
         *JD-Core Version:1.1.3
